<template>
	<view class="container" :style="{ height: wanlsys.windowHeight + 'px'}">
		<!-- #ifdef MP-WEIXIN -->

		<!-- #endif -->
		<!-- #ifndef MP-WEIXIN -->
		<swiper class="swiper-banner" :style="{ top: wanlsys.height - 5 + 'px' }" :indicator-dots="true"
			:autoplay="true" :interval="3000" :duration="1000" circular indicator-color="#ffffff70"
			indicator-active-color="#fff">
		<!-- #endif -->

			<!-- #ifdef MP-WEIXIN -->
			<swiper class="swiper-banner" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000"
				circular indicator-color="#ffffff70" indicator-active-color="#fff">
			<!-- #endif -->
				<swiper-item v-for="(item, index) in adoptData.show_images" :key="index">
					<view class="swiper-item">
						<view class="swiper-item-bg bg-img"
							:style="{ backgroundImage: 'url(' + $wanlshop.oss(item) + ')' }">
						</view>
						<image :src="$wanlshop.oss(item)" mode="aspectFit"></image>
					</view>
				</swiper-item>
			</swiper>
			<view class="wrap" :style="{'--bg': common.appStyle.home_nav_color}">
				<view class="pet">
					<view class="bg-img avatar"
						:style="{ backgroundImage: 'url(' + $wanlshop.oss(adoptData.pet_avatar) + ')' }">
					</view>

					<view class="right">
						<view class="name">
							<text>{{adoptData.pet_name}}</text>
							<image class="sex-img" v-if="adoptData.pet_sex == 'M'"
								src="/static/images/adopt/男.png" mode="widthFix"></image>
							<image class="sex-img" v-if="adoptData.pet_sex == 'F'"
								src="/static/images/adopt/女.png" mode="widthFix"></image>
							<text class="text-sm text-gray" v-if="adoptData.pet_sex == 'O'">其他</text>
						</view>

						<view class="tags">
							<view class="tag" v-for="item in adoptData.tag">{{item}}</view>
						</view>
					</view>
				</view>

				<!-- 宠物信息 -->
				<view class="pet-info">
					<view class="pet-info-item" v-for="(item,index) in adoptData.pet_info" :key="index">
						<view class="pet-title">
							<!-- <view class="bg-img pet-icon" :style="{ backgroundImage: 'url(' + $wanlshop.oss(item.icon) + ')' }"></view> -->
							<view class="bg-img pet-icon">
								<image :src="item.icon" :style="{ width: '30rpx', height: '30rpx' }"></image>
							</view>
							<text>{{item.title}}</text>
						</view>
						<view class="info">
							{{item.value}}
						</view>
					</view>
				</view>

				<!-- 关于宠物 -->
				<view class="pet-about">
					<view class="title">关于宠物</view>
					{{adoptData.description}}
				</view>

			</view>

			<view class="wanlian cu-bar tabbar foot flex flex-direction">
				<button v-if="adoptData.adoption_status == 0" @tap="adopt_handle"
					class="cu-btn round lg wanl-bg-theme">预约领养</button>
				<button v-if="adoptData.adoption_status == 1" class="cu-btn round lg wanl-bg-theme"
					style="opacity: 0.8">已预约</button>
				<button v-if="adoptData.adoption_status == 2" class="cu-btn round lg wanl-bg-theme">已领养</button>
			</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from 'vuex';
	export default {
		data() {
			return {
				wanlsys: {},
				adoptData: {
					images: [],
				},
				pdNumber: 0,
				details: {}
			};
		},
		onLoad(e) {
			this.wanlsys = this.$wanlshop.wanlsys();
			this.loadData(e.id)
		},
		computed: {
			...mapState(['common']),
		},
		methods: {
			// 获取宠物详情
			async loadData(id) {
				this.$api.get({
					url: '/wanlshop/pet/detail?id=' + id,
					success: res => {
						console.log('res', res)
						res.show_images = res.show_images.split(',');
						res.tag = res.tag.split(',');
						res.pet_info = [{
								title: '品种',
								value: res.pet_varieties,
								icon: '../../static/images/adopt/variety.png'
							},
							{
								title: '年龄',
								value: res.pet_age,
								icon: '../../static/images/adopt/age.png'
							},
							{
								title: '体重',
								value: res.pet_weight,
								icon: '../../static/images/adopt/weight.png'
							},
							{
								title: '绝育',
								value: res.pet_fertility_text,
								icon: '../../static/images/adopt/procreate.png'
							},
							{
								title: '疫苗',
								value: res.pet_vaccine_text,
								icon: '../../static/images/adopt/vaccine.png'
							},
							{
								title: '驱虫',
								value: res.pet_drug_text,
								icon: '../../static/images/adopt/insectRepellent.png'
							}
						]

						this.adoptData = res;
						console.log('res', res)
					}
				});
			},
			adopt_handle() {
				if (this.$store.state.user.isLogin) {
					this.$wanlshop.to(`/pages/adopt/information?id=${this.adoptData.id}`, 'fade-in', 100);
				} else {
					this.$wanlshop.msg('请登录')
					setTimeout(() => {
						uni.navigateTo({
							url: '/pages/user/auth/name'
						})
					}, 300)
				}
			}
		},
	}
</script>

<style scoped lang="scss">
	.wanlian.cu-bar.tabbar {
		background-color: #ffffff;
		// 上外阴影
		box-shadow: -100rpx 0 100rpx 100rpx #ffffff;
	}

	.wanlian.cu-bar.tabbar .cu-btn {
		width: calc(100% - 50rpx);
	}

	.wanlian.cu-bar.tabbar .cu-btn.lg {
		font-size: 32rpx;
		height: 86rpx;
	}

	.container {
		position: relative;
		width: 100%;
		padding-bottom: 180rpx;

		.swiper-banner {
			width: 100%;
			// background-color: greenyellow;

			position: fixed;
			top: 0;
			// left: 0;
			height: 50%;
			// z-index: 0;

			.swiper-item {
				height: 100%;
				// border: 1px solid red;
				position: relative;

				.swiper-item-bg {
					width: 100%;
					height: 100%;
					position: absolute;
					top: 0;
					left: 0;
					filter: blur(20rpx);
					transform: scale(1.2);
				}

				image {
					width: 100%;
					height: 100%;
					display: block;
				}
			}
		}

		.wrap {
			position: absolute;
			top: 50%;
			z-index: 1;
			width: 100%;
			background-color: var(--bg);
			padding: 20rpx;
			padding-bottom: 240rpx;

			.pet {
				width: 100%;
				display: flex;
				gap: 20rpx;
				margin-bottom: 20rpx;
				background-color: #fff;
				padding: 20rpx;
				border-radius: 12rpx;

				.avatar {
					width: 100rpx;
					height: 100rpx;
					border-radius: 12rpx;
					flex-shrink: 0;
				}

				.right {
					display: flex;
					flex-direction: column;
					justify-content: space-between;

					.name {
						font-size: 36rpx;
						color: #3D3D3D;
						display: flex;
						gap: 10rpx;
						align-items: center;
						margin-bottom: 6rpx;

						.sex-img {
							width: 30rpx;
							height: 30rpx;
						}
					}

					.tags {
						display: flex;
						gap: 10rpx;
						flex-wrap: wrap;

						.tag {
							background-color: #F2F2F2;
							color: #5C3734;
							padding: 4rpx 10rpx;
							border-radius: 8rpx;
							font-size: 24rpx;
							width: fit-content;
							border: 2rpx solid #846966;
						}
					}
				}
			}

			.pet-info {
				width: 100%;
				display: grid;
				grid-template-columns: repeat(3, 1fr);
				gap: 20rpx;
				margin-bottom: 20rpx;
				background-color: #fff;
				padding: 20rpx;
				border-radius: 12rpx;

				.pet-info-item {
					background-color: #f6f6f6;
					padding: 16rpx;
					box-sizing: border-box;
					border-radius: 12rpx;

					.pet-title {
						display: flex;
						align-items: center;
						gap: 10rpx;
						margin-bottom: 10rpx;

						.pet-icon {
							width: 30rpx;
							height: 30rpx;
						}

						text {
							font-size: 20rpx;
							color: #9C9C9C;
						}
					}

					.info {
						color: #3D3D3D;
						font-size: 24rpx;
						// text-align: center;
					}
				}
			}

			.pet-about {
				background-color: #fff;
				border-radius: 20rpx;
				padding: 20rpx 30rpx;

				text {
					font-size: 24rpx;
					color: #9C9C9C;
				}
			}
		}

		.title {
			font-size: 24rpx;
			color: #3D3D3D;
			margin-bottom: 20rpx;
			font-weight: bold;
		}

	}
</style>